#include "process.h"
#define NUM 101
#define STYLE '='
double total = 1024.0;
double speed = 1.0;
 void  process_v1()
{
  char buffer[NUM];
  memset(buffer,0,sizeof(buffer));
  int cnt=0;
  const char *lable= "|/-\\";
  int len = strlen(lable);
  while(cnt<=100)
  {
    printf("[%-100s],[%d%%],[%c]\r",buffer,cnt,lable[cnt%len]);
    fflush(stdout);
    buffer[cnt]=STYLE;
    cnt++;
    usleep(50000);
  }
}
void FlushProcess(double total,double current)
{
  char buffer [NUM] ;
  memset(buffer,0,sizeof(buffer));
  const char *lable="/|\\";
  int len = strlen(lable);
  static int cnt = 0;
  int num = (int)(current*100/total);//百分比
  int i = 0;
  for(;i<num;i++)
      { 
           buffer[i]=STYLE;
      }
  double rate = current/total;
  cnt %=len;
  printf("[%-100s][%.1f%%][%c]\r",buffer,rate*100,lable[cnt]);
  cnt++;
  fflush(stdout);
}

void Download()
{
 double current = 0;
 while(current <= total)
 {
   FlushProcess(total,current);
   usleep(3000);
   current += speed;

 }
 printf("\ndownload %.2lfMB Done\n",current);
}

int main()
{
 
Download();



  return 0;

}
